package lao_db

import (
	"gorm.io/gorm"
	"log"
)

const (
	Mysql string = "mysql"
)

var supportDbs = []string {
	Mysql,
}

var dbs = make(map[string]*gorm.DB)

func init () {
	log.Println("start to init dbs >>>>>>")
	log.Printf("current support dbs: %v", supportDbs)

	for _, v := range supportDbs {
		loader, ok := loaders[v]
		if !ok || loader == nil {
			log.Printf("db: %v are not supported now \n", v)
			continue
		}

		db, err := loader.load()
		if err != nil {
			log.Fatalf("failed to init db %v - err: %v\n", v, err)
		}

		dbs[v] = db
	}
}

func GetDB(name string) *gorm.DB {
	return dbs[name]
}





